//app.js
App({
  onLaunch: function (options) {
    wx.cloud.init({
      env:'mtl-0g9n8kd147f879e9',
      traceUser: true
    })
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    //启动时获取参数
   
    
  },
  onShow:function (options){

    
    if(options.referrerInfo.extraData){
      let title2 = "appjs 说明从其他小程序跳过来 并 携带 openid:" + options.referrerInfo.extraData.ownerCarryOpenid;
      // let title2 = "appjs 说明从其他小程序跳过来 并 携带 openid:" + options.referrerInfo.extraData.ownerCarryOpenid;
      console.log(title2);
      
      // 业主跳转过来 携带的商家id
     this.globalData.ownerCarryMerchantId = options.referrerInfo.extraData.ownerCarryMerchantId;
      // 业主跳转过来携带的 openid  
     this.globalData.ownerCarryOpenid = options.referrerInfo.extraData.ownerCarryOpenid;
    }
      

    this.getOpenid();
  },
  globalData: {
    /**     全局用户 重要参数/
     *  userType
     *  
     */
    userInfo: null,
    ownerCarryMerchantId:'0',// 业主跳转过来 携带的商家id
    ownerCarryOpenid:'0',// 业主跳转过来携带的 openid   
    ownerCarryAppid:'0',// 业主跳转过来携带的 appid   
  },
  // 获取用户openid
  getOpenid() {

    if(this.globalData.ownerCarryOpenid != '0'){// 说明从其他小程序跳过来 并 携带 openid
      console.log("说明从其他小程序跳过来 并 携带 openid",this.globalData.ownerCarryOpenid);
      let title = "说明从其他小程序跳过来 并 携带 openid:"+this.globalData.ownerCarryOpenid;
      wx.showToast({
        title:title,
        icon: 'none',
        duration: 3300,
      });
      wx.setStorageSync('openid', this.globalData.ownerCarryOpenid)
      wx.setStorageSync('appid', this.globalData.ownerCarryAppid)
      return;
    }

    wx.cloud.callFunction({
      name: 'getOpenid',
      complete: res => {
        if (res) {
          wx.setStorageSync('openid', res.result.openid)
          console.log('app.js__openid', res.result.openid);
          
          wx.setStorageSync('appid', res.result.appid)
          console.log('app.js__appid', res.result.appid);
          
        }
      }
    })
  },
})